#ifndef EGG_LOG_H
#define EGG_LOG_H

#include "StringUtil.h"

namespace egg {

    class Log {
    public:
        enum LogChar {
            FLUSH,
            ENDL,
        };
    public:
        Log(const string& name, bool debugOutput, bool fileOutput);
        ~Log();
        void toggle(bool t);
        void logMessage(const string& message);
        void setFileOutput(bool fileOutput);
        void setDebugOutput(bool debugOutput);
        void setTimeStamp(bool timeStamp);
        const string& getName() const;

        template <typename T>
        Log& operator<<(const T& v) {
            mCache << v;
            return *this;
        }

        Log& operator<<(LogChar c) {
            if (c == FLUSH) {
                logMessage(mCache.str());
                mCache.str("");
                return *this;
            }
            if (c == ENDL) {
                mCache << '\n';
                return *this;
            }
        }


    protected:
        bool mToggle;
        bool mDebugOutput;
        bool mFileOutput;
        bool mTimeStamp;
        string mName;
        ofstream mfpLog;
        stringstream mCache;
    };

    typedef map<string,Log*> LogMap;
}

#endif
